package com.py.androidUtils.UI.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.py.androidUtils.UI.model.PositionView;
import com.py.androidUtils.base.BaseCommAdapter;
import com.readyidu.app.R;

public class PositionAdapter extends BaseCommAdapter<PositionView> {
	private LayoutInflater inflater;

	public PositionAdapter(Context context) {
		inflater = LayoutInflater.from(context);
	}

	@SuppressLint("InflateParams")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = inflater.inflate(R.layout.common_position_item, null);
			holder.title = (TextView) convertView.findViewById(R.id.title);
			holder.content = (TextView) convertView.findViewById(R.id.content);
			holder.selectImages = (ImageView) convertView.findViewById(R.id.selectImages);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		PositionView positionView = (PositionView) listData.get(position);
		if (positionView.isSelect()) {
			holder.selectImages.setVisibility(View.VISIBLE);
		} else {
			holder.selectImages.setVisibility(View.GONE);
		}
		holder.title.setText(positionView.getTitle() == null ? "" : positionView.getTitle());
		if (positionView.getContent() != null) {
			holder.content.setText(positionView.getContent() == null ? "" : positionView.getContent());
			holder.content.setVisibility(View.VISIBLE);
		} else {
			holder.content.setVisibility(View.GONE);
		}
		return convertView;
	}

	private final class ViewHolder {
		private TextView title;
		private TextView content;
		private ImageView selectImages;
	}
}
